package com.xinzhi.service.impl;

import com.baomidou.mybatisplus.generator.config.IFileCreate;
import com.xinzhi.mapper.RecordMapper;
import com.xinzhi.mapper.UseroperationMapper;
import com.xinzhi.pojo.Idnumber;
import com.xinzhi.pojo.Incomeandexpenditurerecord;
import com.xinzhi.service.IRecardService;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class RecardServiceImpl implements IRecardService {
    @Autowired
    private RecordMapper recordMapper;
    @Autowired
    private UseroperationMapper useroperationMapper;
    @Override
    public Result addRecard(Incomeandexpenditurerecord incomeandexpenditurerecord) {
        //检查数据是否合法
        if (incomeandexpenditurerecord.getUserId() == null) {
            throw new RuntimeException("账户id不能为空");
        }
        //检查交易类型是否合法
        if (incomeandexpenditurerecord.getTransactionType() == null) {
            throw new RuntimeException("交易类型不能为空");
        }
        //检查交易金额是否合法
        if (incomeandexpenditurerecord.getAmount() == null) {
            throw new RuntimeException("交易金额不能为空");
        }

        //执行插入操作
        recordMapper.insertRecord(incomeandexpenditurerecord);
        return Result.ok();
    }

    @Override
    public Result selectal(String username) {
        if (username == null)
          return   Result.error("用户名不能为空");
        Idnumber getal = useroperationMapper.getal(username);
        return getal!=null? Result.ok(getal) : Result.error("用户不存在");
    }
}

